﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace iPdf
{
    abstract class CloudStorageService
    {
        //the flag to show if the user is logged in
        protected bool loggedIn;
        protected List<string> folders = new List<string>();
        protected string serviceName;
        protected FileFormat supportedFileFormats = new FileFormat();
        #region Properties
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public bool LoggedIn
        {
            get
            {
                return loggedIn;
            }
        }

        public virtual List<string> Folders
        {
            get
            {
                return new List<string>();
            }
        }

        public FileFormat SupportedFileFormats
        {
            get
            {
                return supportedFileFormats;
            }
        }

        public virtual IValidator UsernameValidator
        {
            get
            {
                return new EmailAddressValidator();
            }
        }

        public virtual IValidator PasswordValidator
        {
            get
            {
                return new PasswordValidator();
            }
        }

        #endregion

        #region Ctor

        public CloudStorageService()
        {
            folders.Add(global::iPdf.Properties.Resources.RootFolder);
        }
        #endregion

        #region Methods

        /// <summary>
        /// log in to the service
        /// </summary>
        /// <param name="username">The username</param>
        /// <param name="password">The password</param>
        /// <returns></returns>
        public abstract void Login(string username, string password);

        public virtual void Logout()
        {
            loggedIn = false;
        }

        /// <summary>
        /// upload a file to the service
        /// </summary>
        /// <param name="fileName">the file to be uploaded</param>
        /// <returns></returns>
        public virtual void Upload(string fileName)
        {
            if(string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                throw new FileAccessFailed(fileName);
            }
        }

        public override string ToString()
        {
            return serviceName;
        }

        #endregion
    }
}

